﻿#pragma once
// Copyright (c) lanyeo 2020-2021
// Licenced under MIT license. See https://opensource.org/licenses/MIT for details.
// code style
// 1. use forward declaration (尽可能使用前置声明)
// 2. include file sequence [other project>c>c++>third>self project]
//

#include <core/manager.h>

#include <list>

#include <google/protobuf/message.h>
#include <cppcoro/task.hpp>

struct DBConf;

class IDBManager : public IManager
{
public:
    virtual const DBConf* conf() = 0;
};

class IDBOperator
{
public:
    virtual int Init() = 0;
    virtual int TryConnect() = 0;
    virtual void Tick() = 0;
    virtual void Destroy() = 0;

    virtual int Insert(google::protobuf::Message* data) = 0;
    virtual cppcoro::task<int> CoInsert(google::protobuf::Message* data) = 0;

    virtual int Delete(google::protobuf::Message* data) = 0;
    virtual cppcoro::task<int> CoDelete(google::protobuf::Message* data) = 0;
    virtual int Delete(const std::string& sql) = 0;
    virtual cppcoro::task<int> CoDelete(const std::string& sql) = 0;

    virtual int Update(google::protobuf::Message* data) = 0;
    virtual cppcoro::task<int> CoUpdate(google::protobuf::Message* data) = 0;
    virtual int Update(const std::string& sql) = 0;
    virtual cppcoro::task<int> CoUpdate(const std::string& sql) = 0;

    virtual int Replace(google::protobuf::Message* data) = 0;
    virtual cppcoro::task<int> CoReplace(google::protobuf::Message* data) = 0;
    virtual int Replace(const std::string& sql) = 0;
    virtual cppcoro::task<int> CoReplace(const std::string& sql) = 0;

    virtual cppcoro::task<int> Select(const std::string& sql, google::protobuf::Message* what,
                                      std::list<google::protobuf::Message*>& results) = 0;
};